package com.letoken.platform.repo.admin.manager;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.letoken.platform.repo.admin.dao.AnnouncementMapper;
import com.letoken.platform.repo.admin.po.Announcement;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author wyl
 * @date 2023/1/1 18:03
 * @Version 1.0
 */
@Log4j2
@Repository
public class AnnouncementManager {

    @Autowired
    private AnnouncementMapper announcementMapper;

    public boolean queryCountByPidAndLang(Long pid,String lang){
        LambdaQueryWrapper<Announcement> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(Announcement::getPid,pid).eq(Announcement::getLang,lang);
        Integer count = announcementMapper.selectCount(wrapper);
        return count >= 1;
    }

    public List<Announcement> queryListByPid(Long pid){
        LambdaQueryWrapper<Announcement> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(Announcement::getPid,pid);
        return announcementMapper.selectList(wrapper);

    }

    public int delListByPid(Long pid){
        LambdaQueryWrapper<Announcement> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(Announcement::getPid,pid);
        return announcementMapper.delete(wrapper);

    }
}
